//
//  ShadowViewController.m
//  DebugDemo
//
//  Created by XFB on 2019/5/24.
//  Copyright © 2019 ZhouCheng. All rights reserved.
//

#import "ShadowViewController.h"

@interface ShadowViewController ()

@property (nonatomic, strong) UIView *shadowView;
@property (nonatomic, strong) UIView *whiteView;

@end

@implementation ShadowViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = UIColorFromRGB(0xEEEEEE);
    self.navigationItem.title = @"Shadow阴影";
    
    [self setupUI];
    
}

- (void)setupUI
{
    UIView *viewBG = [[UIView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenW, ScreenH)];
    viewBG.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:viewBG];
    
    self.shadowView = [[UIView alloc] initWithFrame:CGRectMake(20, NavBarHeight + 30, ScreenW-40, 200)];
    self.shadowView.layer.cornerRadius = 5;
    [self.view addSubview:self.shadowView];
    
    self.whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW-40, 200)];
    self.whiteView.layer.cornerRadius = 5;
    self.whiteView.layer.masksToBounds = YES;
    self.whiteView.backgroundColor = [UIColor orangeColor];
    [self.shadowView addSubview:self.whiteView];

//    [self addShadow:self.shadowView];
    [self addShadowToView:self.shadowView withColor:UIColorFromRGB(0xEEEEEE)];
//    [self addShadowToView:self.shadowView withColor:[UIColor orangeColor]];
}

- (void)addShadow:(UIView *)view
{
//    view.layer.shadowColor = UIColorFromRGB(0xCCCCCC).CGColor;  //shadowColor阴影颜色
    view.layer.shadowColor = [UIColor orangeColor].CGColor; //shadowColor阴影颜色
    view.layer.shadowOffset = CGSizeMake(0, 5); //shadowOffset阴影偏移，默认(0, -3),这个跟shadowRadius配合使用
    view.layer.shadowOpacity = 0.8; //0.8;//阴影透明度，默认0
    view.layer.shadowRadius = 5;    //8;//阴影半径，默认3

    //路径阴影
    UIBezierPath *path = [UIBezierPath bezierPath];

    float width = view.bounds.size.width;
    float height = view.bounds.size.height;
    float x = view.bounds.origin.x;
    float y = view.bounds.origin.y;
    
    CGPoint topLeft      = view.bounds.origin;
    CGPoint topRight     = CGPointMake(x + width, y);
    CGPoint bottomRight  = CGPointMake(x + width, y + height);
    CGPoint bottomLeft   = CGPointMake(x, y + height);
    
    [path moveToPoint:CGPointMake(topRight.x, topRight.y)];
    [path addLineToPoint:CGPointMake(bottomRight.x, bottomRight.y)];
    [path addLineToPoint:CGPointMake(bottomLeft.x, bottomLeft.y)];
    [path addLineToPoint:CGPointMake(topLeft.x, topLeft.y)];
    //设置阴影路径
    view.layer.shadowPath = path.CGPath;
}

- (void)addShadowToView:(UIView *)theView withColor:(UIColor *)theColor
{
    // 阴影颜色
//    theView.layer.shadowColor = theColor.CGColor;
//    // 阴影偏移，默认(0, -3)
//    theView.layer.shadowOffset = CGSizeMake(0, 5);
//    // 阴影透明度，默认0
//    theView.layer.shadowOpacity = 1;
//    // 阴影半径，默认3 shadowRadius 和 shadowOffset 一起使用
//    theView.layer.shadowRadius = 5;
    
    theView.layer.shadowOffset = CGSizeZero;//默认为0,-3
    theView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    theView.layer.shadowOpacity = 0.8;//阴影透明度，默认0
    
}

@end
